#include "uiInfo.h"

#include <Poco/String.h>
#include <stdexcept>
#include <string>
#include <sstream>
#include <iomanip>
#include "server/net/NetworkControl.h"
#include "misc/Interface.h"
/*********************************************************/
void uiInfo::execute()
{
	if ( parsed ) {
		// Get an instance of the network controller & interface
		NetworkControl& nc = NetworkControl::Instance();
		Interface& intf = Interface::Instance();

		std::ostringstream	ostr;

		ostr << "Address: " << nc.getLocalAddress() << std::endl;
		ostr << "Hash: " << nc.getLocalHash() << std::endl;
		ostr << "Predecessor: " << nc.getPredecessor() << std::endl;
		ostr << "Successor: " << nc.getSuccessor() << std::endl;
		intf << ostr.str();
		intf.flush();
	}
}
/*********************************************************/
void uiInfo::parseOptions(std::vector<std::string>& arguments)
{
	Interface& intf = Interface::Instance();

	if ( arguments.size() != 0 ) {
		if ( arguments[0] == " ?" ) {
			helpInfo();
		} else if ( arguments[0] == "" ) {
			parsed = true;
		} else {
			intf << "Invalid usage of info, use info ? to get usage information" << std::endl;
			intf.flush();
		}
	}

	if ( arguments.size() == 0 ) {
		parsed = true;
	}
}
/*********************************************************/
void uiInfo::helpInfo()
{
	Interface& intf = Interface::Instance();

	// Print help information for the execute command
	intf << "info usage: info" << std::endl;
	intf << "info provides an overview of the current middleware configuration parameters" << std::endl;
	intf.flush();
}
/*********************************************************/
